<!--模型分类列表 开始-->
<div id="sort_list">
    <div class="modal-header">
        <span class="modal-title"><i class="fas fa-info-circle mr-1"></i>{$module_rs.title} {:lang('v_sort')}</span>
        <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span></button>
    </div>
    <div class="modal-body">
        <div class="w-100 mb-3">
            <form name="form_checksearch" id="form_checksearch">
                <input type="hidden" name="lang" id="lang" value="{:input('lang')}">
                <input type="hidden" name="tabledir" value="{:input('tabledir')}">
                <div class="input-group">
                    <input name="keyword" id="keyword" placeholder="{:lang('v_quickfind')}" type="text" class="form-control">
                    <span class="input-group-append">
                        <button id="search_sort" type="button" class="btn btn-success"><i class="fas fa-search mr-1"></i>{:lang('v_search')}</button>
                    </span>
                </div>
            </form>
        </div>
        <table class="table table-striped table-bordered table-hover">
            <tr>
                <td width="120" class="overflow-hidden">{:lang('v_title')}</td>
                <td>{:lang('v_linkurl')}</td>
                <td width="80" class="text-center overflow-hidden">{:lang('v_do')}</td>
            </tr>
            {volist name="list" id="rs"}
                {php}$id = $rs['id']; $haveChild = 'no';{/php}
                <tr id="tr_{$rs.id}">
                    <td id="td_{$rs.id}">
                        {tag:list name="childRs" table="sort" where="parentid=$id" limit="1" order="id desc"}
                            {php}$haveChild = 'yes';{/php}
                        {/tag:list}
                        {if $haveChild eq 'yes'}
                            <?php
                                if(in_array(config('global.url.category'),array(0,2))){
                                    $display_urlroute = $rs['table_urlroute'];
                                }else{
                                    $display_urlroute = $rs['urlroute'];
                                }
                            ?>
                            <a onclick="javascript:display_child({$rs.id},'{$rs.title}','{$display_urlroute}');" href="javascript:void(0);">{$rs.title|msubstr=0,8}<i class="fas fa-plus-square fa-lg ml-2"></i></a>
                        {else /}
                            {$rs.title|msubstr=0,8}
                        {/if}
                    </td>
                    {if input('client') eq 'app'}
                        <td>/pages/{$rs.tabledir}/index?sortid={$rs.id}</td>
                        <td class="text-center"><button class="btn btn-sm btn-default" onclick="javascript:check_close('/pages/{$rs.tabledir}/index?sortid={$rs.id}');">{:lang('v_select')}</button></td>
                    {else /}
                        <td><a href="{$rs.urlroute}" target="_blank">{$rs.urlroute}</a></td>
                        <td class="text-center"><button class="btn btn-sm btn-default" onclick="javascript:check_close('{$rs.urlroute}');">{:lang('v_select')}</button></td>
                    {/if}
                </tr>
            {/volist}
        </table>
        <div class="row">
            <div class="col-md-12 mt-2">
                {eq name="module_rs.sort_style" value="2"}
                    <div class="float-left mr-4">{$list->render()|raw}</div>
                    <div class="float-left mt-2">{:lang('v_total')} {$lastPage} {:lang('v_page')} {$total} {:lang('v_records')}</div>
                {else /}
                    {:lang('v_total')} {$total} {:lang('v_records')}
                {/eq}
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
//翻页
$("#sort_list").delegate(".pagination a","click",function(){
    $.get(this.href,function(html){
        $("#sort_list").replaceWith(html);
    });
    return false;
});
//搜索
$('#search_sort').click(function(){
    var href = '{:url('/navigation/sort',['from'=>'sort','tabledir'=>$tabledir])}&lang='+$('#lang').val()+'&keyword='+$('#keyword').val()+'&client={:input('client')}';
    $.get(href,function(html){
        $("#sort_list").replaceWith(html);
    });
});
//关闭窗口
function check_close(linkurl){
    $('#linkurl').attr('href',linkurl);
    $('input[name="linkurl"]').val(linkurl);
    $("#modal").modal('hide');
}
//点击展开子分类
function display_child(id,title,urlroute=''){
    var html = ''; var hide_id = ''; var tree = '';
    var parentid = '{:input('parentid')}';
    var sortid = '{:input('sortid')}';
    $.ajax({
        type: "POST",
        url: "{:url('common/child')}",
        dataType: "json",
        data: {tabledir:'sort', id:id},
        success: function(data){
            $.each(data,function(i,val){
                tree = '';
                for(var j=0;j<val.level;j++){
                    tree += '|---';
                }
                html += '<tr id="tr_'+val.id+'">';
                if(val.child == 'yes'){
                    <?php if(in_array(config('global.url.category'),array(0,2))){ ?>
                        html += '    <td class="align-middle" id="td_'+val.id+'"><a onclick="javascript:display_child('+val.id+',\''+val.title+'\',\''+urlroute+'\');" href="javascript:void(0);">'+tree+val.title+'<i class="fas fa-plus-square fa-lg ml-2"></i></a></td>';
                    <?php }else{ ?>
                        html += '    <td class="align-middle" id="td_'+val.id+'"><a onclick="javascript:display_child('+val.id+',\''+val.title+'\',\''+urlroute+val.urlroute+"/"+'\');" href="javascript:void(0);">'+tree+val.title+'<i class="fas fa-plus-square fa-lg ml-2"></i></a></td>';
                    <?php } ?>
                }else{
                    html += '    <td class="align-middle">'+tree+val.title+'</td>';
                }
                {if input('client') eq 'app'}
                    html += '<td>/pages/'+val.tabledir+'/index?sortid='+val.id+'</td>';
                    html += '    <td class="text-center align-middle">';
                    html += '    <a href="javascript:void(0);" onclick="javascript:check_close(\'/pages/'+val.tabledir+'/index?sortid='+val.id+'\');" class="btn btn-sm btn-default mb-2">{:lang('v_select')}</a>';
                    html += '    </td>';
                {else /}
                    html += '<td class="text-center"><a href="'+urlroute+val.urlroute+'/" target="_blank">'+urlroute+val.urlroute+'/</a></td>';
                    html += '    <td class="align-middle">';
                    html += '    <a href="javascript:void(0);" onclick="javascript:check_close(\''+urlroute+val.urlroute+'/\');" class="btn btn-sm btn-default mb-2">{:lang('v_select')}</a>';
                    html += '    </td>';
                {/if}
                html += '</tr>';
                hide_id = val.hide_id;
            });
            $('#tr_'+id+'').after(html);
            var parent_tree = tree.substring(0,tree.length-4);
            $('#td_'+id+'').html('<a onclick="javascript:hide_child('+id+',\''+hide_id+'\',\''+title+'\',\''+parent_tree+'\',\''+urlroute+'\');" href="javascript:void(0);">'+parent_tree+title+'<i class="fas fa-plus-square fa-lg ml-2"></i></a>');
        }
    });
}
//点击移除子分类
function hide_child(id,hide_id,title,tree,urlroute=''){
    var hide_id_arr = hide_id.split(',');
    for(var i=0;i<hide_id_arr.length;i++){
        $('#tr_'+hide_id_arr[i]).remove();
    }
    $('#td_'+id+'').html('<a onclick="javascript:display_child('+id+',\''+title+'\',\''+urlroute+'\');" href="javascript:void(0);">'+tree+title+'<i class="fas fa-plus-square fa-lg ml-2"></i></a>');
}
</script>
<!--模型分类列表 结束-->